<template>
  <div class="app-container" id="meteredWarn">
    <el-row style="width: 100%;height: 100%;margin: 0;" :gutter="10">
      <!--区域数据-->
      <el-col :span="4" style="height: 100%;padding-left: 0;">
        <div style="background-color: #FFFFFF;height: 100%;padding: 10px;">
          <el-input placeholder="输入关键字进行过滤" clearable size="mini" suffix-icon="el-icon-search"
                    style="width: 100%;" v-model="filterText"/>
          <div style="height: 96%; max-height:96%;overflow-y: auto;margin-top: 10px;" class="treeCont">
            <el-tree
              :default-expanded-keys="defaultExpandedKeys"
              :data="sheetsTreeList"
              :props="defaultProps"
              :expand-on-click-node="false"
              :filter-node-method="filterNode"
              ref="tree"
              node-key="sheetsCode"
              highlight-current
              v-loading="treeLoading"
              @node-click="handleNodeClick"
            >
              <template #default="{ node, data}">
                <div class="custom-tree-node"
                     style="display: flex;justify-content: center;align-items: center;font-size: 14px;">
                  <span class="iconfont icon-a-jiafangzijianzhu icon-padding" v-if="data.deviceType === 0"></span>
                  <span class="iconfont icon-loudong icon-padding" v-if="data.deviceType === 1"></span>
                  <span class="iconfont icon-a-homezhuyefangzijia icon-padding" v-if="data.deviceType === 2"></span>
                  <span>{{ node.label }}</span>
<!--                  <span v-if="data.deviceCount!=null" class="device-count">{{data.deviceCount}}</span>-->
                </div>
              </template>
            </el-tree>
          </div>
        </div>
      </el-col>
      <!--户表告警数据-->
      <el-col :span="20" style="height: 100%;background-color: #FFFFFF;padding: 5px;">
        <el-row class="line-bottom" v-show="showSearch">
          <el-col class="form_col">
            <el-form :model="queryParams" ref="queryForm" :size="size" v-show="showSearch" :label-width="labelWidth">
              <div id="searchFilter" style="display: flex; flex-wrap: wrap">
                <!-- <el-form-item label="设备类型" prop="terminalType">
                    <el-select
                      :size="formItemSize"
                      v-model="queryParams.terminalType"
                      placeholder="请选择设备类型"
                      filterable
                      @keyup.enter.native="handleQuery"
                      @change="(val) => changeEnergyUseClassification(val)"
                    >
                      <el-option
                        v-for="dict in dict.type.energy_use_classification"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                        :selected="dict.value == 1"
                      />
                    </el-select>
                  </el-form-item> -->
                <el-form-item label="设备编号" prop="terminalId">
                  <el-input
                      v-model="queryParams.terminalId"
                      placeholder="请输入设备编号"
                      clearable
                      size="mini"
                      @keyup.enter.native="handleQuery"
                      style="width: 100%;"
                  />
                </el-form-item>
<!--                <el-form-item label="处理状态" prop="handleStatus">-->
<!--                  <el-select v-model="queryParams.handleStatus" placeholder="请选择处理状态" size="mini">-->
<!--                    <el-option v-for="dict in dict.type.warn_handle_status" :key="dict.value" :label="dict.label"-->
<!--                               :value="dict.value">{{ dict.label }}-->
<!--                    </el-option>-->
<!--                  </el-select>-->
<!--                </el-form-item>-->
                <!-- 时间范围 -->
                <el-form-item label="报警时间" prop="freezeTime">
                  <el-date-picker size="mini" :clearable="false"
                                  v-model="freezeTime"
                                  value-format="yyyy-MM-dd"
                                  type="daterange"
                                  range-separator="-"
                                  start-placeholder="开始日期"
                                  end-placeholder="结束日期"
                                  style="width: 100%;">
                  </el-date-picker>
                </el-form-item>
              </div>
            </el-form>
          </el-col>
          <el-col class="form_query">
            <el-button v-show="collapseAble" type="text" @click="shiftCollapseAble" class="text">
              <span>
                {{ fold ? '收起筛选' : '更多筛选' }}
              </span>
            </el-button>
            <el-button type="primary" @click="handleQuery" size="mini">查询</el-button>
            <el-button @click="resetQuery" size="mini">重置</el-button>
          </el-col>
        </el-row>

        <!-- <el-row :gutter="6" class="mb8 padding_top_bottom">
          <RightDropdown :columns="columns" :showSearch.sync="showSearch" @queryTable="getList" @export="handleExport" :hasPermiExport="['alarmmanagement:warn:export']"></RightDropdown>
        </el-row> -->
        <el-row>
          <el-tabs v-model="activeKey" type="card" size="mini" @tab-click="handleClick">
            <el-tab-pane v-for="item in AlarmType" :name="item.PTypeValue" :key="item.PTypeValue"
                         :label="item.PTypeName" class="ant-tabs">
              <el-table v-loading="loading" :data="warnList" border size="mini"
                        @selection-change="handleSelectionChange" :height="getAvailableHeight"
                        ref="table" :default-sort="defaultSort" @sort-change="handleSorterChange">
                <el-table-column type="index" label="#" width="40" align="center"/>
                <!-- <el-table-column label="平台主键" align="center" prop="id" :show-overflow-tooltip="true" />
                <el-table-column label="租户ID" align="center" prop="tenantId" :show-overflow-tooltip="true" /> -->
                <!--                <el-table-column label="报警对象类型" align="center" prop="targetType" width="120"-->
                <!--                                 :show-overflow-tooltip="true">-->
                <!--                  <template slot-scope="scope">-->
                <!--                    <dict-tag :options="dict.type.warntargettype" :value="scope.row.targetType"/>-->
                <!--                  </template>-->
                <!--                </el-table-column>-->
                <el-table-column label="设备编号" align="center" prop="terminalId" width="150"
                                 :show-overflow-tooltip="true" sortable="custom"
                                 :sort-orders="['ascending', 'descending']"/>
                <!--                <el-table-column label="报警对象名称" align="center" prop="targetName" width="150"-->
                <!--                                 :show-overflow-tooltip="true"/>-->
                <!-- ，0未确认，1已确认 -->
<!--                <el-table-column label="报警状态" align="center" prop="warnStatus" :show-overflow-tooltip="true"-->
<!--                                 sortable="custom" :sort-orders="['ascending', 'descending']">-->
<!--                  <template slot-scope="scope">-->
<!--                    <dict-tag :options="dict.type.warn_status" :value="scope.row.warnStatus"/>-->
<!--                  </template>-->
<!--                </el-table-column>-->
<!--                &lt;!&ndash; ，0未处理，1已处理 &ndash;&gt;-->
<!--                <el-table-column label="处理状态" align="center" prop="handleStatus" :show-overflow-tooltip="true"-->
<!--                                 sortable="custom" :sort-orders="['ascending', 'descending']">-->
<!--                  <template slot-scope="scope">-->
<!--                    <dict-tag :options="dict.type.warn_handle_status" :value="scope.row.handleStatus"/>-->
<!--                  </template>-->
<!--                </el-table-column>-->
                <el-table-column label="报警类型" align="center" prop="warnParamType" :show-overflow-tooltip="true"
                                 width="140" sortable="custom" :sort-orders="['ascending', 'descending']">
                  <template slot-scope="scope">
                    <dict-tag :options="dict.type.warn_param_type" :value="scope.row.warnParamType"/>
                  </template>
                </el-table-column>
                <!-- ，1超上限，2超下限，3阈值，4累计，5连续 -->
                <!--                <el-table-column label="报警类型" align="center" prop="warnType" :show-overflow-tooltip="true">-->
                <!--                  &lt;!&ndash; <template slot-scope="scope">-->
                <!--                    <dict-tag :options="dict.type.warnparamtype" :value="scope.row.warnType"/>-->
                <!--                  </template> &ndash;&gt;-->
                <!--                </el-table-column>-->
                <el-table-column label="报警时间" align="center" prop="freezeTime" width="180"
                                 :show-overflow-tooltip="true" sortable="custom"
                                 :sort-orders="['ascending', 'descending']">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.freezeTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="异常时间" align="center" prop="recentlyWartTime" width="180"
                                 :show-overflow-tooltip="true" sortable="custom"
                                 :sort-orders="['ascending', 'descending']">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.recentlyWarnTime, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
<!--                <el-table-column label="异常时间" align="center" prop="startTime" width="180"-->
<!--                                 :show-overflow-tooltip="true" sortable="custom"-->
<!--                                 :sort-orders="['ascending', 'descending']">-->
<!--                  <template slot-scope="scope">-->
<!--                    <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>-->
<!--                  </template>-->
<!--                </el-table-column>-->
                <!--                <el-table-column label="最近报警时间" align="center" prop="recentlyWarnTime" width="180"-->
                <!--                                 :show-overflow-tooltip="true">-->
                <!--                  <template slot-scope="scope">-->
                <!--                    <span>{{ parseTime(scope.row.recentlyWarnTime, '{y}-{m}-{d}') }}</span>-->
                <!--                  </template>-->
                <!--                </el-table-column>-->
                <!--                <el-table-column label="数据冻结时间" align="center" prop="freezeTime" width="180"-->
                <!--                                 :show-overflow-tooltip="true">-->
                <!--                  <template slot-scope="scope">-->
                <!--                    <span>{{ parseTime(scope.row.freezeTime, '{y}-{m}-{d}') }}</span>-->
                <!--                  </template>-->
                <!--                </el-table-column>-->
                <el-table-column label="报警值" align="center" prop="warnValue" :show-overflow-tooltip="true"
                                 width="180" sortable="custom" :sort-orders="['ascending', 'descending']"/>
                <el-table-column label="参考值" align="center" prop="referenceValue" :show-overflow-tooltip="true"
                                 sortable="custom" :sort-orders="['ascending', 'descending']"/>
                <el-table-column label="差值" align="center" prop="value" :show-overflow-tooltip="true"
                                 sortable="custom" :sort-orders="['ascending', 'descending']"/>
                <!--                <el-table-column label="确认人" align="center" prop="confirmedBy" :show-overflow-tooltip="true"/>-->
                <!--                <el-table-column label="派单状态" align="center" prop="pd" :show-overflow-tooltip="true"/>-->
                <!--                <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120"-->
                <!--                                 fixed="right">-->
                <!--                  <template slot-scope="scope">-->
                <!--                    <el-button-->
                <!--                        size="mini"-->
                <!--                        type="text"-->
                <!--                        icon="el-icon-edit"-->
                <!--                        @click="handleUpdate(scope.row)"-->
                <!--                        v-hasPermi="['alarmmanagement:warn:edit']"-->
                <!--                    >-->
                <!--                    </el-button>-->
                <!--                    <el-button-->
                <!--                        size="mini"-->
                <!--                        type="text"-->
                <!--                        icon="el-icon-delete"-->
                <!--                        @click="handleDelete(scope.row)"-->
                <!--                        v-hasPermi="['alarmmanagement:warn:remove']"-->
                <!--                    >-->
                <!--                    </el-button>-->
                <!--                  </template>-->
                <!--                </el-table-column>-->
              </el-table>

              <pagination :total="total"
                          :page.sync="queryParams.pageNum"
                          :limit.sync="queryParams.pageSize"
                          @pagination="getList"
              />
            </el-tab-pane>
          </el-tabs>
        </el-row>

        <!--        <el-row>-->
        <!--          <el-col :span="4">-->
        <!--            <el-button-->
        <!--                type="danger"-->
        <!--                plain-->
        <!--                icon="el-icon-delete"-->
        <!--                size="mini"-->
        <!--                :disabled="multiple"-->
        <!--                @click="handleDelete"-->
        <!--                v-hasPermi="['alarmmanagement:warn:remove']"-->
        <!--            >批量处理-->
        <!--            </el-button>-->
        <!--          </el-col>-->
        <!--          <el-col :span="20">-->
        <!--            <pagination-->
        <!--                v-show="total>0"-->
        <!--                :total="total"-->
        <!--                :page.sync="queryParams.pageNum"-->
        <!--                :limit.sync="queryParams.pageSize"-->
        <!--                @pagination="getList"-->
        <!--            />-->
        <!--          </el-col>-->
        <!--        </el-row>-->
      </el-col>
    </el-row>


    <!-- 添加或修改告警对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="680px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" :label-width="labelWidth" :inline="true">
        <!-- <el-form-item label="租户编号" prop="tenantId">
          <el-input v-model="form.tenantId" placeholder="请输入租户编号" />
        </el-form-item> -->
        <el-form-item label="归属水司" prop="tenantId">
          <el-select v-model="form.tenantId" placeholder="请选择归属水司" style="width: 202px;">
            <el-option
                v-for="dict in dict.type.belong_department"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value.toString()"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="报警对象类型" prop="targetType">
          <el-select v-model="form.targetType" placeholder="请选择报警对象类型">
            <el-option
                v-for="dict in dict.type.warntargettype"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="报警对象" prop="targetId">
          <el-input v-model="form.targetId" placeholder="请输入报警对象ID"/>
        </el-form-item>
        <el-form-item label="报警对象名称" prop="targetName">
          <el-input v-model="form.targetName" placeholder="请输入报警对象名称"/>
        </el-form-item>
        <el-form-item label="报警参数" prop="warnParamType">
          <el-select v-model="form.warnParamType" placeholder="请选择报警参数">
            <el-option
                v-for="dict in dict.type.warnparamtype"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-date-picker clearable
                          v-model="form.startTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="异常时间" prop="recentlyWarnTime">
          <el-date-picker clearable
                          v-model="form.recentlyWarnTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择异常时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报警时间" prop="freezeTime">
          <el-date-picker clearable
            v-model="form.freezeTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择报警时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报警值-实际数值" prop="warnValue">
          <el-input v-model="form.warnValue" placeholder="请输入报警值-实际数值"/>
        </el-form-item>
        <el-form-item label="参考值" prop="referenceValue">
          <el-input v-model="form.referenceValue" placeholder="请输入参考值"/>
        </el-form-item>
        <el-form-item label="差值" prop="Value">
          <el-input v-model="form.Value" placeholder="请输入差值"/>
        </el-form-item>
        <el-form-item label="确认人" prop="confirmedBy">
          <el-input v-model="form.confirmedBy" placeholder="请输入确认人"/>
        </el-form-item>
        <el-form-item label="派单状态" prop="pd">
          <el-input v-model="form.pd" placeholder="请输入派单状态"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getDicts } from '@/api/system/dict/data.js'
import moment from 'moment'
import {listxbWarn, getWarn, delWarn, addWarn, updateWarn} from "@/api/alarm/alarmall";
import {getAreasList} from '@/api/basedata/areas'
import {listMeterSheetsTree} from "@/api/basedata/meterSheets";

export default {
  name: "MeteredWarn",
  dicts: ['warnparamtype', 'warntargettype', 'warn_handle_status', 'warn_status', 'warn_param_type', 'belong_department'],
  data() {
    return {
      // 默认展开项
      defaultExpandedKeys: [],
      screenHeight: null,
      // 按钮状态
      buttonAll: false,
      buttonStress: true,
      buttonAccumulative: true,
      buttonData: true,
      buttonCommunication: true,
      buttonEmpty: true,
      buttonVoltmetre: true,
      buttonDays: true,
      buttonMagnet: true,
      buttonInstant: true,
      size: 'mini',
      collapseAble: false,
      fold: false,
      maxShow: '3',
      labelWidth: '80px',
      // 异常时间区间
      freezeTime: [moment().subtract(1, 'day').format('YYYY-MM-DD'), moment().subtract(1, 'day').format('YYYY-MM-DD')],
      // 列信息
      // columns: [
      //   { key: 0, label: `平台主键`, visible: false },
      //   { key: 1, label: `租户ID`, visible: true },
      //   { key: 2, label: `报警对象类型`, visible: true },
      //   { key: 3, label: `报警对象`, visible: true },
      //   { key: 4, label: `报警对象名称`, visible: true },
      //   { key: 5, label: `报警状态`, visible: true },
      //   { key: 6, label: `处理状态`, visible: true },
      //   { key: 7, label: `报警参数`, visible: true },
      //   { key: 8, label: `报警类型`, visible: true },
      //   { key: 9, label: `开始时间`, visible: true },
      //   { key: 10, label: `最近报警时间`, visible: true },
      //   { key: 11, label: `数据冻结时间`, visible: true },
      //   { key: 12, label: `报警值-实际数值`, visible: true },
      //   { key: 13, label: `确认人`, visible: true },
      //   { key: 14, label: `差值`, visible: true },
      //   { key: 15, label: `确认人`, visible: true },
      //   { key: 16, label: `派单状态`, visible: true },
      // ],
      // 默认排序
      defaultSort: {prop: 'startTime', order: 'descending'},
      defaultProps: {
        children: "children",
        label: "sheetsName"
      },
      // 区域树选项
      sheetsTreeList: [],
      // 遮罩层
      loading: true,
      treeLoading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 告警表格数据
      warnList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        id: null,
        sheetsCode: null,
        tenantId: null,
        targetType: 1,
        terminalType:2,
        targetId: null,
        targetName: null,
        warnStatus: null,
        // handleStatus: null,
        warnParamType: null,
        warnType: null,
        beginStartTime: null,
        endStartTime: null,
        freezeTime: null,
        warnValue: null,
        referenceValue: null,
        Value: null,
        confirmedBy: null,
        pd: null,
       // terminalType: "1",
      },
      // tabs
      activeKey: '',
      AlarmType: [
        {PTypeValue: '', PTypeName: '全部类型'},
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        tenantId: [
          {required: true, message: "归属水司不能为空", trigger: "change"}
        ],
        targetType: [
          {required: true, message: "报警对象类型不能为空", trigger: "change"}
        ],
        targetId: [
          {required: true, message: "报警对象不能为空", trigger: "blur"}
        ],
        targetName: [
          {required: true, message: "报警对象名称不能为空", trigger: "blur"}
        ],
        warnStatus: [
          {required: true, message: "报警状态", trigger: "change"}
        ],
        // handleStatus: [
        //   {required: true, message: "处理状态", trigger: "change"}
        // ],
        warnParamType: [
          {required: true, message: "报警参数", trigger: "change"}
        ],
        startTime: [
          {required: true, message: "开始时间不能为空", trigger: "blur"}
        ],
      },
      filterText: ''
    };
  },
  watch: {
    // 根据名称筛选部门树
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  created() {
    this.getTreeList();
    this.screenHeight = document.body.clientHeight
    this.getAlarmType()
  },
  computed: {
    getAvailableHeight() {
      return this.screenHeight - 265
    },
  },
  mounted() {
    this.getList();
  },
  methods: {
    changeEnergyUseClassification(val) {
      console.log(val + "，我是val");

      this.queryParams.terminalType = val;
    },
    // 获取报警类型数据
    getAlarmType(){
      getDicts('warn_param_type').then(res => {
        if(res.code === 200) {
          res.data.forEach(item => {
            if(item.remark.substr(0,1) === 'E'){
              let obj = {
                PTypeValue: item.dictValue,
                PTypeName: item.dictLabel
              }
              this.AlarmType.push(obj)
            }
          })
        }
      })
    },
    /** 排序触发事件 */
    handleSorterChange({column, prop, order}) {
      this.queryParams.orderByColumn = prop
      this.queryParams.isAsc = order
      this.getList()
    },
    /** 检查设置排序字段 */
    checkSortColumn() {
      if (!this.queryParams.orderByColumn) {
        this.queryParams.orderByColumn = this.defaultSort.prop
        this.queryParams.isAsc = this.defaultSort.order
      }
    },
    handleClick(tab) {
      this.queryParams.warnParamType = tab._props.name
      this.handleQuery()
    },
    // 展开折叠按钮
    shiftCollapseAble() {
      this.fold = !this.fold
      this.minShowControl()
    },
    // 通过maxShow控制元素显示/折叠
    minShowControl() {
      const group = window.document.querySelectorAll(`#searchFilter .el-form-item.el-form-item--${this.size}`)
      const len = group?.length ? group?.length - 1 : 0
      if (this.maxShow < len) {
        group.forEach((item, index) => {
          if (index > this.maxShow - 1 && index < len) {
            item.hidden = !this.fold
          }
        })
        this.collapseAble = true
      } else {
        this.collapseAble = false
      }
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.sheetsName.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.handleQuery();
    },
    /** 查询区域树 */
    getTreeList() {
      this.treeLoading = true;
      // listMeterSheetsTree({}).then(response => {
      //   this.sheetsTreeList = response;
      //   this.treeLoading = false;
      // });
      this.sheetsTreeList = JSON.parse(localStorage.getItem('meteredTreeData'))
      if(this.sheetsTreeList.length === 0) {
        this.treeLoading = false;
      }else {
        this.defaultExpandedKeys = [this.sheetsTreeList[0].sheetsCode];
        this.treeLoading = false;
      }
    },
    /** 查询告警列表 */
    getList() {
      this.checkSortColumn()
      this.loading = true;
      if (this.freezeTime.length > 0) {
        this.queryParams.beginStartTime = this.freezeTime[0]
        this.queryParams.endStartTime = this.freezeTime[1]
      }
      const sheetsCode = this.$refs.tree.getCurrentKey()
      if (sheetsCode) {
        this.queryParams.sheetsCode = sheetsCode
      }
      listxbWarn(this.queryParams).then(response => {
        this.warnList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tenantId: null,
        targetType: null,
        targetId: null,
        targetName: null,
        warnStatus: null,
        // handleStatus: null,
        warnParamType: null,
        warnType: null,
        startTime: null,
        beginStartTime: null,
        endStartTime: null,
        Value: null,
        confirmedBy: null,
        recentlyWarnTime: null,
        freezeTime: null,
        warnValue: null,
        referenceValue: null,
        value: null,
        pd: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.freezeTime = [moment().subtract(1, 'day').format('YYYY-MM-DD'), moment().subtract(1, 'day').format('YYYY-MM-DD')]
      this.resetForm("queryForm");
      this.$refs.tree.setCurrentKey(null)
      this.queryParams.sheetsCode = ''
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加告警";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWarn(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改告警";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWarn(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWarn(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const IDs = row.id || this.ids;
      this.$modal.confirm('是否确认删除告警编号为"' + IDs + '"的数据项？').then(function () {
        return delWarn(IDs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('alarmmanagement/warn/export', {
        ...this.queryParams
      }, `warn_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-tabs__item.is-active {
  color: rgb(255, 255, 255);
  background-color: #409eff !important;
}

.form_col {
  width: 80%;

  ::v-deep .el-form {
    width: 100%;
  }

  ::v-deep .el-form-item {
    width: 25%;
  }
}

.form_query {
  width: 20%;
  text-align: right;
}
// 设置本身箭头为隐藏状态
::v-deep .el-tree-node__expand-icon {
  width: 20px;
  padding: 0;
  margin: 5px 0;

  svg {
    display: none;
    width: 0;
  }
}

// 虚线所需样式
::v-deep .treeCont {
  .el-tree-node{
    width: fit-content;
  }
  .el-tree > .el-tree-node:before {
    //border-top: none;
    padding-left: 0px;
  }

  .el-tree > .el-tree-node:after {
    border-top: none;
  }

  .el-tree-node__content {
    padding-left: 5px !important;
  }

  .el-tree-node__children {
    //overflow: visible !important;
    .el-tree-node {
      position: relative;
      padding-left: 5px;
    }
  }

  //节点有间隙，隐藏掉展开按钮就好了,如果觉得空隙没事可以删掉
  .el-tree-node__expand-icon.is-leaf {
    width: 4px;
  }

  .el-tree-node__children {
    padding-left: 18px;
  }

  .el-tree-node :last-child:before {
    height: 17px;
  }

  .el-tree > .el-tree-node:before {
    border-left: none;
  }

  .el-tree > .el-tree-node:after {
    border-top: none;
    top: 25px;
    width: 0px;
  }

  .el-tree-node:before {
    content: "";
    left: -4px;
    position: absolute;
    right: auto;
    border-width: 1px;
  }

  .el-tree-node:after {
    content: "";
    left: -4px;
    position: absolute;
    right: auto;
    border-width: 1px;
  }

  .el-tree-node:before {
    border-left: 1px dashed #c0c4cc;
    height: 100%;
    top: -3px;
    width: 1px;
  }

  .el-tree-node:after {
    border-top: 1px dashed #c0c4cc;
    height: 0px;
    top: 13px;
    width: 16px;
  }
}

// 默认三角行换成加减号
::v-deep .treeCont {
  .el-tree-node__content > .el-tree-node__expand-icon {
    width: 16px;
    //width: 0px;
    padding: 0px;
    font-size: 16px !important;
    margin-right: 5px; //新增
  }

  .el-tree .el-tree-node__expand-icon.expanded {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }

  //有子节点 且未展开
  .el-tree .el-tree-node__expand-icon:before {
    background: url('../../../assets/images/jia.png') no-repeat;
    content: "";
    display: block;
    width: 20px;
    height: 20px;
    font-size: 20px;
    background-size: 100% 100%;
  }

  .custom-tree-node .el-icon svg {
    display: block !important;
    color: #000;
  }

  //有子节点 且已展开
  .el-tree .el-tree-node__expand-icon.expanded:before {
    background: url('../../../assets/images/jian.png') no-repeat;
    content: "";
    display: block;
    width: 20px;
    height: 20px;
    font-size: 20px;
    background-size: 100% 100%;
  }

  //没有子节点
  .el-tree .el-tree-node__expand-icon.is-leaf::before {
    background: none;
    content: "";
    display: block;
    width: 20px;
    height: 20px ;
    font-size: 20px;
    background-size: 100% 100%;
  }
}
</style>
